package com.ny.demo03;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class EmployeeDao {
    private static DBUntil dbUntil = new DBUntil();
    Connection connection= dbUntil.getConnection();

    public EmployeeDao() throws SQLException, ClassNotFoundException {
    }
    public Employee insertEmployee(Employee employee) throws SQLException {
        String sql = "INSERT INTO employee (name, age, department) VALUES (?, ?, ?)";
        PreparedStatement pstm = connection.prepareStatement(sql);
        pstm.setString(1, employee.getName());
        pstm.setInt(2, employee.getAge());
        pstm.setString(3, employee.getDepartment());
        int i = pstm.executeUpdate();
        if (i > 0) {
            System.out.println("添加成功");
        } else {
            System.out.println("添加失败");
        }
        return employee;
    }

}
